package br.ufrn.dca.interfaceGrafica;

import br.ufrn.dca.controle.PID;
import br.ufrn.dca.controle.QuanserClient;
import br.ufrn.dca.controle.QuanserClientException;
import br.ufrn.dca.graficos.*;
import br.ufrn.dca.identificacao.Rele;
import br.ufrn.dca.identificacao.Degrau;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
import org.jfree.chart.ChartUtilities;

public class JanelaPrincipal extends javax.swing.JFrame {

    /**
     * Janela de configurações
     */
    JanelaConfig jc;
    /**
     * Grafico
     */
    Grafico gd = new Grafico("Grafico");
    /**
     * Grafico para a resposta ao degrau;
     *
     */
    GraficoDegrau grd = new GraficoDegrau("Gráfico");
    List<Boolean> graficos = new ArrayList<Boolean>();
    /**
     * Cliente para comunicação com a planta
     */
    QuanserClient qc;
    /**
     * Controla o fluxo de janelas e ações no software
     */
    Fluxo fluxo;
    // Variaveis controladoras de tempo
    Timer contador;
    double tempoInicial;
    double tempoAtual = 0.0;
    double tempoFinal = 0.0;
    /**
     * Formatador dos numeros apresentados na interface
     */
    private DecimalFormat formatador = new DecimalFormat("#0.00");
    /**
     * Varaivel resposavel pela contagem do numero de graficos salvas
     */
    private int contPrint = 1;
    /**
     * Variavel que referência a classe Rele
     */
    private Rele rele;
    /**
     * Sensibilidade dos sensores
     */
    private double ks = 6.25;
    /**
     * Valor de set point
     */
    private double ref;
    /**
     * Controlador PID
     */
    private PID pid;

    /**
     * Creates new form JanelaPrincipal
     */
    public JanelaPrincipal() {
        initComponents();
        this.setLocationRelativeTo(null);
        graficos.add(true);  // Pos 0 = PV( Volts ) - Nivel T1 (cm)
        graficos.add(true);  // Pos 1 = Sinal de erro( Volts ) - (cm)
        graficos.add(true);  // Pos 2 = Set-Point( cm )
        graficos.add(true);  // Pos 3 = Sinal Escrito ( Volts )
        gd.pack();
        this.graficoPanel.add(gd.getContentPane());
        this.jc = new JanelaConfig(this, true, this);
        this.fluxo = new Fluxo();
        //Criando modelo para o spinner da referencia      
        SpinnerNumberModel model = new SpinnerNumberModel(15, 0.0, 28, 0.1);
        RefSpinner.setModel(model);
        this.rele = new Rele(fluxo);
        this.pid = new PID();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel6 = new javax.swing.JPanel();
        graficoPanel = new javax.swing.JPanel();
        jPanelConfig = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        NivelTanque2Label = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        NivelTanque1Label = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        NivelTanque1Label1 = new javax.swing.JLabel();
        NivelTanque1Label2 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        RefSpinner = new javax.swing.JSpinner();
        RefButton = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        RefAtualLabel = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        SintControlButton = new javax.swing.JButton();
        ganhoKLabel4 = new javax.swing.JLabel();
        ganhoKLabel5 = new javax.swing.JLabel();
        ganhoKLabel6 = new javax.swing.JLabel();
        KpLabel = new javax.swing.JLabel();
        KiLabel = new javax.swing.JLabel();
        KdLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        ganhoKLabel = new javax.swing.JLabel();
        TaoLabel = new javax.swing.JLabel();
        DelayLabel = new javax.swing.JLabel();
        ganhoKLabel1 = new javax.swing.JLabel();
        DelayLabel1 = new javax.swing.JLabel();
        TaoLabel1 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        ReleButton = new javax.swing.JButton();
        ganhoKLabel2 = new javax.swing.JLabel();
        ganhoKLabel3 = new javax.swing.JLabel();
        AmpLabel = new javax.swing.JLabel();
        PeriodoLabel = new javax.swing.JLabel();
        BarraMenu = new javax.swing.JMenuBar();
        MenuConfig = new javax.swing.JMenu();
        ConfigurarMenu = new javax.swing.JMenuItem();
        ConectarMenu = new javax.swing.JMenuItem();
        DesconectarjMenu = new javax.swing.JMenuItem();
        MenuGrafico = new javax.swing.JMenu();
        LimparjMenu = new javax.swing.JMenuItem();
        SalvarjMenu = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        DegrauMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SICMR");
        setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 12)); // NOI18N

        graficoPanel.setLayout(new java.awt.BorderLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Nível", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial Unicode MS", 1, 12))); // NOI18N
        jPanel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N

        NivelTanque2Label.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        NivelTanque2Label.setText("0.00");

        jLabel1.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        jLabel1.setText("Tanque 1 -");

        NivelTanque1Label.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        NivelTanque1Label.setText("0.00");

        jLabel5.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        jLabel5.setText("Tanque 2 -");

        NivelTanque1Label1.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        NivelTanque1Label1.setText("cm");

        NivelTanque1Label2.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        NivelTanque1Label2.setText("cm");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(NivelTanque2Label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(NivelTanque1Label, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(NivelTanque1Label1)
                    .addComponent(NivelTanque1Label2))
                .addContainerGap(34, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(NivelTanque1Label)
                    .addComponent(NivelTanque1Label1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(NivelTanque2Label)
                    .addComponent(NivelTanque1Label2))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Referência", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial Unicode MS", 1, 12))); // NOI18N

        RefSpinner.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N

        RefButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        RefButton.setText("Alterar");
        RefButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RefButtonActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        jLabel6.setText("Valor Atual:");

        RefAtualLabel.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        RefAtualLabel.setText("00.00 cm");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(RefSpinner)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(RefAtualLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(RefButton))
                .addContainerGap(14, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RefSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(RefButton, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 18, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(RefAtualLabel)))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Controlador", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial Unicode MS", 1, 12))); // NOI18N

        SintControlButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        SintControlButton.setText("Sintonizar");
        SintControlButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SintControlButtonActionPerformed(evt);
            }
        });

        ganhoKLabel4.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ganhoKLabel4.setText("Kp -");

        ganhoKLabel5.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ganhoKLabel5.setText("Ki  -");

        ganhoKLabel6.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ganhoKLabel6.setText("Kd -");

        KpLabel.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        KpLabel.setText("0.00");

        KiLabel.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        KiLabel.setText("0.00");

        KdLabel.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        KdLabel.setText("0.00");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(ganhoKLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(KpLabel))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(ganhoKLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(KiLabel))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(ganhoKLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(SintControlButton)
                            .addComponent(KdLabel))))
                .addContainerGap(49, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ganhoKLabel4)
                    .addComponent(KpLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ganhoKLabel5)
                    .addComponent(KiLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ganhoKLabel6)
                    .addComponent(KdLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(SintControlButton, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Constantes da Planta", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial Unicode MS", 1, 12))); // NOI18N
        jPanel2.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N

        ganhoKLabel.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ganhoKLabel.setText("0.00");

        TaoLabel.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        TaoLabel.setText("0.00");

        DelayLabel.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        DelayLabel.setText("0.00");

        ganhoKLabel1.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ganhoKLabel1.setText("Ganho  -");

        DelayLabel1.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        DelayLabel1.setText("Delay   -");

        TaoLabel1.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        TaoLabel1.setText("Constante de tempo -");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(DelayLabel1)
                            .addComponent(ganhoKLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(DelayLabel)
                            .addComponent(ganhoKLabel)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(TaoLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TaoLabel)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ganhoKLabel)
                    .addComponent(ganhoKLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DelayLabel1)
                    .addComponent(DelayLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TaoLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(TaoLabel))
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Sistema", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial Unicode MS", 1, 12))); // NOI18N

        ReleButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ReleButton.setText("Identificar");
        ReleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReleButtonActionPerformed(evt);
            }
        });

        ganhoKLabel2.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ganhoKLabel2.setText("Período - ");

        ganhoKLabel3.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ganhoKLabel3.setText("Amplitude -");

        AmpLabel.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        AmpLabel.setText("0.00");

        PeriodoLabel.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        PeriodoLabel.setText("0.00");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(ReleButton))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                        .addComponent(ganhoKLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                        .addComponent(AmpLabel))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                        .addComponent(ganhoKLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(PeriodoLabel)))
                .addGap(56, 56, 56))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ganhoKLabel2)
                    .addComponent(PeriodoLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ganhoKLabel3)
                    .addComponent(AmpLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(ReleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanelConfigLayout = new javax.swing.GroupLayout(jPanelConfig);
        jPanelConfig.setLayout(jPanelConfigLayout);
        jPanelConfigLayout.setHorizontalGroup(
            jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanelConfigLayout.setVerticalGroup(
            jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelConfigLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addComponent(jPanelConfig, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(graficoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 850, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelConfig, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(graficoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        MenuConfig.setText("Conexão");
        MenuConfig.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        MenuConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuConfigActionPerformed(evt);
            }
        });

        ConfigurarMenu.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ConfigurarMenu.setText("Configuração");
        ConfigurarMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ConfigurarMenuActionPerformed(evt);
            }
        });
        MenuConfig.add(ConfigurarMenu);

        ConectarMenu.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ConectarMenu.setText("Conectar");
        ConectarMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ConectarMenuActionPerformed(evt);
            }
        });
        MenuConfig.add(ConectarMenu);

        DesconectarjMenu.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        DesconectarjMenu.setText("Desconectar");
        DesconectarjMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DesconectarjMenuActionPerformed(evt);
            }
        });
        MenuConfig.add(DesconectarjMenu);

        BarraMenu.add(MenuConfig);

        MenuGrafico.setText("Gráfico");
        MenuGrafico.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N

        LimparjMenu.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        LimparjMenu.setText("Limpar");
        LimparjMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LimparjMenuActionPerformed(evt);
            }
        });
        MenuGrafico.add(LimparjMenu);

        SalvarjMenu.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        SalvarjMenu.setText("Salvar");
        SalvarjMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SalvarjMenuActionPerformed(evt);
            }
        });
        MenuGrafico.add(SalvarjMenu);

        BarraMenu.add(MenuGrafico);

        jMenu1.setText("Degrau");
        jMenu1.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N

        DegrauMenuItem.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        DegrauMenuItem.setText("Resposta ao Degrau");
        DegrauMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DegrauMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(DegrauMenuItem);

        BarraMenu.add(jMenu1);

        setJMenuBar(BarraMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void RefButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RefButtonActionPerformed
        // TODO add your handling code here:                
        ref = Double.parseDouble(RefSpinner.getValue().toString());
        String aux = formatador.format(ref);
        aux = aux.replace(",", ".");
        this.RefAtualLabel.setText(aux + " cm");
    }//GEN-LAST:event_RefButtonActionPerformed

    private void MenuConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuConfigActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_MenuConfigActionPerformed

    private void ConfigurarMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConfigurarMenuActionPerformed
        // TODO add your handling code here:
        if (!fluxo.isConectado()) {
            JDialog.setDefaultLookAndFeelDecorated(true);
            jc.dispose();
            jc = new JanelaConfig(this, true, this);
            jc.setVisible(true);
        } else {
            JOptionPane.showMessageDialog(this, "É necessário desconectar para alterar configuração!", "Configurações", 1);
        }
    }//GEN-LAST:event_ConfigurarMenuActionPerformed

    private void ConectarMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConectarMenuActionPerformed
        // TODO add your handling code here:
        if (!fluxo.isConectado()) {
            if (!fluxo.isConfigurado()) {
                JOptionPane.showMessageDialog(this, "Configurações ainda não realizadas", "Conectar", 1);
            } else {
                try {
                    qc = new QuanserClient(fluxo.getHost(), fluxo.getPorta());
                    fluxo.setConectado(true);
                    JOptionPane.showMessageDialog(this, "Conexão realizada com sucesso!", "Conectar", 1);
                } catch (QuanserClientException ex) {
                    JOptionPane.showMessageDialog(this, "Não foi possível se conectar com o servidor!", "Conectar", 2);
                }
            }
        } else {
            JOptionPane.showMessageDialog(this, "É necessário desconectar para criar uma nova conexão", "Conectar", 1);
        }
    }//GEN-LAST:event_ConectarMenuActionPerformed

    private void DesconectarjMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DesconectarjMenuActionPerformed
        // TODO add your handling code here:
        desconecte("");
    }//GEN-LAST:event_DesconectarjMenuActionPerformed

    private void LimparjMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LimparjMenuActionPerformed
        // TODO add your handling code here:
        limpaGrafico();
    }//GEN-LAST:event_LimparjMenuActionPerformed

    private void SalvarjMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SalvarjMenuActionPerformed
        // TODO add your handling code here:
        salvarGrafico();
    }//GEN-LAST:event_SalvarjMenuActionPerformed

    private void ReleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReleButtonActionPerformed
        // TODO add your handling code here:
        if (!fluxo.isConectado()) {
            JOptionPane.showMessageDialog(this, "Conexão com o servidor ainda não realizada.", "Sintonizar via Relé", 1);
        } else {
            if (fluxo.isExecutandoRele()) {
                JOptionPane.showMessageDialog(this, "O método de sintonia está em execução.", "Sintonizar via Relé", 1);
            } else {

                limpaGrafico();
                pararComSeguranca();
                tempoFinal = Double.valueOf(tempoAtual);
                fluxo.setExecutandoControlador(false);
                fluxo.setExecutandoRele(true);
                rele.reset();
                pid.reset();
                limparLabel();


                rele.reset();
                fluxo.setExecutandoRele(true);
                ActionListener sintoniaViaRele = new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        double nivelT2 = getNivelT2();
                        double nivelT1 = getNivelT1();
                        double saida = 0;
                        saida = rele.oscilar(nivelT2, (tempoAtual / 1000));
                        enviarSinal(saida);
                        gd.adicionarValores(tempoAtual / 1000,0, nivelT2, 0, rele.getRef(), saida);
                        tempoAtual = (tempoFinal + ((Double) (System.currentTimeMillis() - tempoInicial)));
                        atualizarLabels(getNivelT1(), getNivelT2());
                    }
                };

                tempoInicial = System.currentTimeMillis();
                contador = new Timer(100, sintoniaViaRele);
                contador.start();
            }
        }
    }//GEN-LAST:event_ReleButtonActionPerformed

    private void SintControlButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SintControlButtonActionPerformed
//         TODO add your handling code here:
        if (fluxo.isExecutandoRele()) {
            JOptionPane.showMessageDialog(this, "Método de identificação está em execução", "Sintonizar", 1);
        } else {
            if (!fluxo.isSitemaIdentificado()) {
                JOptionPane.showMessageDialog(this, "Sistema ainda não foi identificado", "Sintonizar", 1);
            } else {
                limpaGrafico();
                pararComSeguranca();

                double k = rele.getNopdt().getK();
                double d = rele.getNopdt().getDelay();
                double tao = rele.getNopdt().getTao();
                double ku = rele.getNopdt().getKu();
                double pu = rele.getPu();
                pid.sintonizar(k, d, tao, ku, pu);
                fluxo.setControladorSintonizado(true);

                fluxo.setExecutandoControlador(true);
                ActionListener Pid = new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        double nivelT2 = getNivelT2();
                        double nivelT1 = getNivelT1();

                        double saida = pid.controlePID(ref, nivelT1, nivelT2);
                        enviarSinal(saida);
                        gd.adicionarValores(tempoAtual / 1000, 0, nivelT2, (ref - nivelT2), ref, saida);
                        tempoAtual = (tempoFinal + ((Double) (System.currentTimeMillis() - tempoInicial)));
                        atualizarLabels(getNivelT1(), getNivelT2());
                    }
                };
                tempoInicial = System.currentTimeMillis();
                contador = new Timer(100, Pid);
                contador.start();
            }
        }
    }//GEN-LAST:event_SintControlButtonActionPerformed

    private void DegrauMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DegrauMenuItemActionPerformed
        // TODO add your handling code here:
        if (!fluxo.isConectado()) {
            JOptionPane.showMessageDialog(this, "Conexão com o servidor ainda não realizada.", "Degrau", 1);
        } else if (fluxo.isExecutandoRele()) {
            JOptionPane.showMessageDialog(this, "O método de sintonia está em execução.", "Degrau", 1);
        } else if (fluxo.isExecutandoControlador()) {
            JOptionPane.showMessageDialog(this, "Controlador está em execução", "Degrau", 1);
        } else {

            grd.pack();
            this.graficoPanel.add(grd.getContentPane());
            fluxo.setExecutandoDegrau(true);
            final Degrau d = new Degrau(1);
            ActionListener degrau = new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    double nivelT2 = getNivelT2();
                    enviarSinal(d.getU());
                    grd.adicionarValores(tempoAtual / 1000, nivelT2);
                    tempoAtual = (tempoFinal + ((Double) (System.currentTimeMillis() - tempoInicial)));
                    atualizarLabels(getNivelT1(), getNivelT2());
                }
            };

            tempoInicial = System.currentTimeMillis();
            contador = new Timer(100, degrau);
            contador.start();
        }
    }//GEN-LAST:event_DegrauMenuItemActionPerformed

    /**
     * Desconecta do servidor da planta
     *
     * @param msg
     */
    public void desconecte(String msg) {
        fluxo.setExecutandoRele(false);
        limpaGrafico();
        
        if (fluxo.isConectado()) {
            fluxo = new Fluxo();
            pararComSeguranca();
            fluxo.setConectado(false);
            limparLabel();
        }
        JOptionPane.showMessageDialog(this, "Desconectado do servidor." + msg, "Desconectar", 1);
    }

    /**
     * Limpa o gráfico atual
     */
    private void limpaGrafico() {
        if (!fluxo.isExecutandoRele()) {
            gd = new Grafico("Gráfico");
            gd.pack();
            this.graficoPanel.removeAll();
            this.graficoPanel.add(gd.getContentPane());
            gd.setSize(graficoPanel.getSize().width + 8, graficoPanel.getSize().height + 31);
            tempoInicial = System.currentTimeMillis();
            tempoAtual = 0.0;
            tempoFinal = 0.0;
        }
    }

    /**
     * Para a comunicação com a planta
     */
    private void pararComSeguranca() {
        if (contador != null) {
            contador.stop();
        }
        try {
            qc.write(0, 0);
        } catch (QuanserClientException ex) {
            Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
        tempoFinal = Double.valueOf(tempoAtual);
    }

    /**
     * Salva o grafico que está sendo exibido na tela
     */
    private void salvarGrafico() {
        try {
            OutputStream imagem = new FileOutputStream("grafico_" + this.contPrint + ".png");
            try {
                if (fluxo.isExecutandoDegrau()) {
                    ChartUtilities.writeChartAsPNG(imagem, grd.getChartPrincipal(), graficoPanel.getWidth(), graficoPanel.getHeight());
                } else {
                    ChartUtilities.writeChartAsPNG(imagem, gd.getChartPrincipal(), graficoPanel.getWidth(), graficoPanel.getHeight());
                }
                contPrint++;
                imagem.close();
                JOptionPane.showMessageDialog(this, "Grafico salvo com sucesso.", "Salvar", 1);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, "Não foi possível salvar o gráfico.", "Salvar", 2);
            }
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(this, "Não foi possível salvar o gráfico.", "Salvar", 2);
        }
    }

    private void limparLabel() {
        
        this.NivelTanque1Label.setText("0.00");
        this.NivelTanque2Label.setText("0.00");
        this.ganhoKLabel.setText("0.00");
        this.TaoLabel.setText("0.00");
        this.DelayLabel.setText("0.00");
        this.KpLabel.setText("0.00");
        this.KiLabel.setText("0.00");
        this.KdLabel.setText("0.00");
        this.AmpLabel.setText("0.00");
        this.PeriodoLabel.setText("0.00");
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception ex) {
                }
                new JanelaPrincipal().setVisible(true);
            }
        });
    }

    public QuanserClient getQc() {
        return qc;
    }

    public void setQc(QuanserClient qc) {
        this.qc = qc;
    }

    public Fluxo getFluxo() {
        return fluxo;
    }

    public void setFluxo(Fluxo fluxo) {
        this.fluxo = fluxo;
    }

    /**
     * Retorna o nivel do tanque 1
     *
     * @return
     */
    public double getNivelT1() {
        try {
            return qc.read(0) * ks;
        } catch (QuanserClientException ex) {
            JOptionPane.showMessageDialog(this, "Erro de comunicação com o servidor", "Erro", 2);
        }
        return 0;
    }

    /**
     * Retorna o nivel do tanque 2
     *
     * @return
     */
    public double getNivelT2() {
        try {
            return (qc.read(1) * ks + Math.random() / 10);
        } catch (QuanserClientException ex) {
            JOptionPane.showMessageDialog(this, "Erro de comunicação com o servidor", "Erro", 2);
        }
        return 0;
    }

    /**
     * Envia para a planta o valor passado como parâmetro
     *
     * @param sinal
     */
    public void enviarSinal(double sinal) {
        try {
            qc.write(0, sinal);
        } catch (QuanserClientException ex) {
            JOptionPane.showMessageDialog(this, "Erro de comunicação com o servidor", "Erro", 2);
        }
    }

    /**
     * Atualiza label's da interface
     *
     * @param nivelTanque1
     * @param nivelTanque2
     */
    public void atualizarLabels(double nivelTanque1, double nivelTanque2) {
        String nivel1 = formatador.format(nivelTanque1);
        nivel1 = nivel1.replace(",", ".");
        String nivel2 = formatador.format(nivelTanque2);
        nivel2 = nivel2.replace(",", ".");
        this.NivelTanque1Label.setText(nivel1);
        this.NivelTanque2Label.setText(nivel2);

        this.ganhoKLabel.setText(formatador.format(rele.getNopdt().getK()).replace(",", "."));
        this.TaoLabel.setText(formatador.format(rele.getNopdt().getTao()).replace(",", "."));
        this.DelayLabel.setText(formatador.format(rele.getNopdt().getDelay()).replace(",", "."));

        this.AmpLabel.setText(formatador.format(rele.getAmp()).replace(",", "."));
        this.PeriodoLabel.setText(formatador.format(rele.getPu()).replace(",", "."));

        this.KpLabel.setText(formatador.format(pid.getKp()).replace(",", "."));
        this.KiLabel.setText(formatador.format(pid.getKi()).replace(",", "."));
        this.KdLabel.setText(formatador.format(pid.getKd()).replace(",", "."));

    }

    public Rele getRele() {
        return rele;
    }

    public void setRele(Rele rele) {
        this.rele = rele;
    }

    public PID getPid() {
        return pid;
    }

    public void setPid(PID control) {
        this.pid = control;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel AmpLabel;
    private javax.swing.JMenuBar BarraMenu;
    private javax.swing.JMenuItem ConectarMenu;
    private javax.swing.JMenuItem ConfigurarMenu;
    private javax.swing.JMenuItem DegrauMenuItem;
    private javax.swing.JLabel DelayLabel;
    private javax.swing.JLabel DelayLabel1;
    private javax.swing.JMenuItem DesconectarjMenu;
    private javax.swing.JLabel KdLabel;
    private javax.swing.JLabel KiLabel;
    private javax.swing.JLabel KpLabel;
    private javax.swing.JMenuItem LimparjMenu;
    private javax.swing.JMenu MenuConfig;
    private javax.swing.JMenu MenuGrafico;
    private javax.swing.JLabel NivelTanque1Label;
    private javax.swing.JLabel NivelTanque1Label1;
    private javax.swing.JLabel NivelTanque1Label2;
    private javax.swing.JLabel NivelTanque2Label;
    private javax.swing.JLabel PeriodoLabel;
    private javax.swing.JLabel RefAtualLabel;
    private javax.swing.JButton RefButton;
    private javax.swing.JSpinner RefSpinner;
    private javax.swing.JButton ReleButton;
    private javax.swing.JMenuItem SalvarjMenu;
    private javax.swing.JButton SintControlButton;
    private javax.swing.JLabel TaoLabel;
    private javax.swing.JLabel TaoLabel1;
    private javax.swing.JLabel ganhoKLabel;
    private javax.swing.JLabel ganhoKLabel1;
    private javax.swing.JLabel ganhoKLabel2;
    private javax.swing.JLabel ganhoKLabel3;
    private javax.swing.JLabel ganhoKLabel4;
    private javax.swing.JLabel ganhoKLabel5;
    private javax.swing.JLabel ganhoKLabel6;
    private javax.swing.JPanel graficoPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanelConfig;
    // End of variables declaration//GEN-END:variables
}
